<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>v-if判断</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>
<body>
    <div id="app"></div>
</body>
<script>
    const app = Vue.createApp({
        data(){
            return{
                message: '好消息'
            }
        },
        methods:{
            onclickmessage(){
                this.message = this.message=='好消息'?'坏消息':'好消息'
            }
        },
        template:`<h2 @click="onclickmessage" v-if="message=='好消息'" class="green">{{message}}</h2>
        <h2 @click="onclickmessage" v-if="message=='坏消息'" class="red">{{message}}</h2>`
    })
    app.mount("#app")
</script>
<style>
    .red{
        color: red;
    }
    .black{
        color: #000;
    }
    .green{
        color: green;
    }
</style>
</html>